﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TrainingsApp.WebModel;
using System.Web.Services;
using System.Web.Script.Services;
using TrainingsApp.Helper;
using TrainingsApp.Model;
using TrainingsApp.Logic;

namespace TrainingsApp.IPADApp.Student2 {
    public partial class Previews : AccountPage {
        protected void Page_Load(object sender, EventArgs e) {

        }


        public override WebModel.Other.AccountMenuType MenuType {
            get { return WebModel.Other.AccountMenuType.Preview; }
        }

        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json, XmlSerializeString = false)]
        public static string GetPriviewList(long ChapterId, int iPageIndex, int iPageSize)
        {
            int iRowCount, iPageCount = -1;
            bool boolIsSucess = true;
            string strBackMessage = string.Empty;
            TS_Preview_Collecion pList = null;
            if (PassPort.IsAuthenticated)
            {
                try
                {
                    Dictionary<string, object> dict = new Dictionary<string, object>();
                    dict.Add("UserId", PassPort.CurrentUser.UserID);
                    dict.Add("ChapterId", ChapterId);
                    pList = TS_Preview_Logic.TS_Preview_StudentListByPaging(dict, iPageSize, iPageIndex);
                    iRowCount = pList.TotalCount;
                    iPageCount = pList.TotalCount % iPageSize == 0 ? pList.TotalCount / iPageSize : pList.TotalCount / iPageSize + 1;
                }
                catch (Exception ex)
                {
                    boolIsSucess = false;
                    strBackMessage = ex.Message.Replace("\r", "").Replace("\n", "");
                }
            }
            else
            {
                boolIsSucess = false;
                strBackMessage = "您已经登录超时，请重新登录系统。";
            }

            return "{" + string.Format("IsSuccess:{0},Msg:'{1}',PageCount:{2},Table:{3}", boolIsSucess.ToString().ToLower(), strBackMessage, iPageCount, JsonHelper.ToStdJson(pList)) + "}";
        }
    }
}